package config

import (
	"gopkg.in/yaml.v2"
	"io/ioutil"
	"log"
)

type SettingStruct struct {

	Debug           	bool

	Server struct {
		Host	    	string
		Port    		string
	}

	Mongodb struct {
		Host 			string		`yaml:"host"`
		Port 			string 		`yaml:"port"`
		DbName  	    string      `yaml:"dbName"`
	}

	Mysql struct {
		Host 			string		`yaml:"host"`
		Port 			string 		`yaml:"port"`
		DbName    		string      `yaml:"dbName"`
		Username 	    string		`yaml:"username"`
		Password    	string		`yaml:"password"`
		Parameter 	  	string		`yaml:"parameter"`
		TablePrefix 	string    	`yaml:"tablePrefix"`
	}

	SecretKey struct {
		Login 			string		`yaml:"login"`
		Captcha			string		`yaml:"captcha"`
	}

}

var Setting = new(SettingStruct)

func init() {

	yamlFile, err := ioutil.ReadFile("config.yml")
	if err != nil {
		log.Printf("Load config error: %v ", err)
		return
	}
	err = yaml.Unmarshal(yamlFile, Setting)
	if err != nil {
		log.Fatalf("Unmarshal error: %v", err)
	}
}